from django.db import models


# Create your models here.


class Commodity(models.Model):
    name = models.CharField(unique=True, max_length=255)
    user = models.ForeignKey('user.User', models.RESTRICT)
    picture = models.CharField(max_length=2000)
    description = models.TextField()
    type_code = models.CharField(max_length=255)
    rent = models.DecimalField(max_digits=10, decimal_places=2)
    deposit = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    trading = models.CharField(max_length=2)
    express_fee = models.DecimalField(max_digits=10, decimal_places=2, blank=True, null=True)
    new_level = models.IntegerField()
    status = models.CharField(max_length=5)
    total_count = models.IntegerField()
    rent_count = models.IntegerField()
    cover = models.CharField(max_length=50)
    title = models.CharField(max_length=255)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    update_time = models.DateTimeField(blank=True, null=True,auto_now=True)

    class Meta:
        managed = False
        db_table = 'commodity'


class Record(models.Model):
    comm = models.ForeignKey(Commodity, models.RESTRICT)
    user = models.ForeignKey('user.User', models.RESTRICT)
    start_time = models.DateTimeField()
    end_time = models.DateTimeField()
    amount = models.IntegerField()
    deposit = models.IntegerField()
    is_tentaled = models.CharField(max_length=1)
    tental_id = models.IntegerField(blank=True, null=True)
    status = models.CharField(max_length=5)
    count = models.IntegerField()
    intact = models.IntegerField()
    damage_amount = models.IntegerField(blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    update_time = models.DateTimeField(blank=True, null=True,auto_now=True)

    class Meta:
        managed = False
        db_table = 'record'


class Remark(models.Model):
    rid = models.ForeignKey(Record, models.CASCADE, db_column='rid')
    remark_desc = models.TextField()
    level = models.CharField(max_length=1)
    photo = models.CharField(max_length=255, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    update_time = models.DateTimeField(blank=True, null=True,auto_now=True)

    class Meta:
        managed = False
        db_table = 'remark'

class Logistics(models.Model):
    lid = models.IntegerField(primary_key=True)
    rid = models.ForeignKey(Record, models.CASCADE, db_column='rid')
    status = models.CharField(max_length=255)
    status_desc = models.CharField(max_length=255)
    log_code = models.CharField(max_length=100)
    company = models.CharField(max_length=20)
    out_or_return = models.CharField(max_length=2)
    tel = models.CharField(max_length=11)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    update_time = models.DateTimeField(blank=True, null=True,auto_now=True)

    class Meta:
        managed = False
        db_table = 'logistics'

class Type(models.Model):
    type_code = models.CharField(max_length=20)
    name = models.CharField(max_length=20)
    parent_code = models.CharField(max_length=20, blank=True, null=True)
    create_time = models.DateTimeField(blank=True, null=True,auto_now_add=True)
    update_time = models.DateTimeField(blank=True, null=True,auto_now=True)

    class Meta:
        managed = False
        db_table = 'type'
